﻿using KinonekoSoftware.CodariaDB.Documents.DataParts.Characters;
using KinonekoSoftware.CodariaDB.Documents.DataParts.Modules.RVE;
using KinonekoSoftware.CodariaDB.Documents.DataParts.Relationships;
using KinonekoSoftware.CodariaDB.Documents.DataParts.Schools;
using KinonekoSoftware.CodariaDB.Documents.DataParts.Story;
using KinonekoSoftware.CodariaDB.Documents.DataParts.Teams;
using KinonekoSoftware.CodariaDB.Documents.Index;
using KinonekoSoftware.CodariaDB.Documents.Story;
using KinonekoSoftware.CodariaDB.Documents.Templates;

namespace KinonekoSoftware.CodariaDB.Documents.DataParts
{
    public static class PartFactory
    {
        public static Part_Modules Create_Modules(string documentID, bool isCreateTemplatedInstance)
        {
            if (isCreateTemplatedInstance)
            {
                return new Part_Modules
                {
                    Id         = ID.Get(),
                    DocumentID = documentID,
                    Blocks = new List<ModuleBlock>
                    {
                        Block_Text.CreateInstance(),
                        Block_Paragraph.CreateInstance(),
                        Block_Switch.CreateInstance(),
                        Block_Numeric.CreateInstance(NumericStyle.Progress),
                        Block_Numeric.CreateInstance(NumericStyle.Degree),
                        Block_Numeric.CreateInstance(NumericStyle.Radar),
                        Block_Color.CreateInstance(),
                    },
                    Rve = Block_RVE.CreateCharacter(),
                };
            }


            return new Part_Modules
            {
                Id         = ID.Get(),
                DocumentID = documentID,
                Blocks     = new List<ModuleBlock>(32),
                Rve        = Block_RVE.CreateCharacter(),
            };
        }

        public static Part_CustomBasic Create_Basic_Custom(string documentID, InstanceCache cache)
        {
            return new Part_CustomBasic
            {
                Id         = ID.Get(),
                DocumentID = documentID,
                Inlines = new List<CompositeItem>
                {
                    InstanceTemplateGenerator.Property("名字", KnownMetadatas.Name, false, cache.Name),
                },
                Blocks = new List<CompositeParagraph>(),
            };
        }
        
        
        public static Part_PlantBasic Create_Basic_Plant(string documentID, InstanceCache cache)
        {
            return new Part_PlantBasic
            {
                Id         = ID.Get(),
                DocumentID = documentID,
                Inlines = new List<CompositeItem>
                {
                    InstanceTemplateGenerator.Property("名字", KnownMetadatas.Name, false, cache.Name),
                },
                Blocks = new List<CompositeParagraph>(),
            };
        }

        public static Part_BulkProperties Create_Detail_Common_BulkProperties(string documentID)
        {
            return new Part_BulkProperties
            {
                Id         = ID.Get(),
                DocumentID = documentID,
                Surveys    = new List<SurveySets>(),
            };
        }

        #region Country

        
        public static Part_CountryGeography Create_Country_Geography(string documentID)
        {
            return new Part_CountryGeography
            {
                Id         = ID.Get(),
                DocumentID = documentID,
            };
        }
        
        public static Part_CountryDiplomacy Create_Country_Diplomacy(string documentID)
        {
            return new Part_CountryDiplomacy
            {
                Id         = ID.Get(),
                DocumentID = documentID,
            };
        }

        #endregion

        #region Common

        public static Part_Story Create_Common_Story(string documentID)
        {
            return new Part_Story
            {
                Id          = ID.Get(),
                Storyboards = new List<Documents.Story.Story>(),
                DocumentID  = documentID,
            };
        }


        public static Part_Epoch Create_Common_Epoch(string documentID)
        {
            return new Part_Epoch
            {
                Id         = ID.Get(),
                DocumentID = documentID,
            };
        }


        public static Part_Story Create_Common_History(string documentID)
        {
            return new Part_Story
            {
                Id         = ID.Get(),
                DocumentID = documentID,
            };
        }

        #endregion

        #region School

        public static Part_SeatInfo Create_School_Seat(string documentID)
        {
            return new Part_SeatInfo
            {
                Id         = ID.Get(),
                DocumentID = documentID,
                Column     = 6,
                Row        = 9,
                Seats      = new List<SeatSlot>(),
            };
        }


        public static Part_TeacherInfo Create_School_Teacher(string documentID) => new Part_TeacherInfo
        {
            Id         = ID.Get(),
            DocumentID = documentID,
            Teachers   = new List<ClassMember>(),
        };


        public static Part_StudentInfo Create_School_Student(string documentID) => new Part_StudentInfo
        {
            Id         = ID.Get(),
            DocumentID = documentID,
            Students   = new List<ClassMember>(),
        };


        public static Part_GangInClass Create_School_GangInClass(string documentID) => new Part_GangInClass
        {
            Id         = ID.Get(),
            DocumentID = documentID,
        };

        public static Part_ClassInfo Create_School_ClassInfo(string documentID) => new Part_ClassInfo
        {
            Id         = ID.Get(),
            DocumentID = documentID,
        };

        public static Part_ClubInfo Create_School_ClubInfo(string documentID) => new Part_ClubInfo
        {
            Id         = ID.Get(),
            DocumentID = documentID,
        };

        public static Part_LeaderInfo Create_School_LeaderInfo(string documentID) => new Part_LeaderInfo
        {
            Id         = ID.Get(),
            DocumentID = documentID,
        };

        #endregion

        #region Character

        public static Part_CharacterDetail Create_Detail_Character(string documentID)
        {
            return new Part_CharacterDetail
            {
                Id          = ID.Get(),
                DocumentID  = documentID,
                Appearances = new List<SurveySets>(),
                Behaviors   = new List<SurveySets>(),
                Images      = new List<ImageRes>(),
                Worships    = new List<Worship>(),
            };
        }


        public static Part_CharacterEquipment Create_Detail_Character_Equipment(string documentID)
        {
            return new Part_CharacterEquipment
            {
                Id                = ID.Get(),
                DocumentID        = documentID,
                Equipments        = new List<string>(),
                PopularEquipments = new List<string>(),
                Abilities         = new List<string>(),
                PopularAbilities  = new List<string>(),
                Items             = new List<string>(),
                PopularItems      = new List<string>(),
            };
        }

        public static Part_Personality Create_Detail_Character_Personality(string documentID)
        {
            return new Part_Personality
            {
                Id          = ID.Get(),
                DocumentID  = documentID,
                Preferences = new List<PreferenceGroup>(),
                Surveys     = new List<SurveySets>(),
            };
        }

        public static Part_CharacterBRGraph Create_Relationship_Character(string documentID)
        {
            return new Part_CharacterBRGraph
            {
                Id         = ID.Get(),
                DocumentID = documentID,

            };
        }

        #endregion


        //-------------------------------------------------------------
        //
        //          Team
        //
        //-------------------------------------------------------------

        #region TeamGrouped

        public static Part_TeamGroupedBasic Create_Team_Grouped_Basic(string id) => new Part_TeamGroupedBasic
        {
            Id         = ID.Get(),
            DocumentID = id,
            Items      = new List<string>(),
        };

        #endregion


        #region TeamParty

        public static Part_PartyBasic Create_Team_Party_Basic(string id) => new Part_PartyBasic
        {
            Id         = ID.Get(),
            DocumentID = id,
        };


        public static Part_PartyDetail Create_Team_Party_Detail(string id) => new Part_PartyDetail
        {
            Id         = ID.Get(),
            DocumentID = id,
        };

        #endregion



        public static DataPart Create(string documentID, DataPartType type, InstanceCache cache, bool isCreateTemplatedInstance)
        {
            return type switch
            {
                DataPartType.Basic_Custom => Create_Basic_Custom(documentID, cache),
                DataPartType.Basic_Plant  => Create_Basic_Plant(documentID, cache),

                DataPartType.Relationship_Character       => Create_Relationship_Character(documentID),
                DataPartType.Detail_Common_BulkProperties => Create_Detail_Common_BulkProperties(documentID),
                DataPartType.Detail_Character_Personality => Create_Detail_Character_Personality(documentID),
                DataPartType.Detail_Character_Equipment   => Create_Detail_Character_Equipment(documentID),
                DataPartType.Detail_Character             => Create_Detail_Character(documentID),

                DataPartType.Detail_Country_Geography => Create_Country_Geography(documentID),
                DataPartType.Detail_Country_Diplomacy => Create_Country_Diplomacy(documentID),




                DataPartType.Detail_School_SeatInfo    => Create_School_Seat(documentID),
                DataPartType.Detail_School_Student     => Create_School_Student(documentID),
                DataPartType.Detail_School_Teacher     => Create_School_Teacher(documentID),
                DataPartType.Detail_School_ClubInfo    => Create_School_ClubInfo(documentID),
                DataPartType.Detail_School_ClassInfo   => Create_School_ClassInfo(documentID),
                DataPartType.Detail_School_LeaderInfo  => Create_School_LeaderInfo(documentID),
                DataPartType.Detail_School_GangInClass => Create_School_GangInClass(documentID),


                DataPartType.Story   => Create_Common_Story(documentID),
                DataPartType.History => Create_Common_History(documentID),
                DataPartType.Epoch   => Create_Common_Epoch(documentID),
                DataPartType.Modules => Create_Modules(documentID, isCreateTemplatedInstance),
                _                    => null,
            };
        }

    }
}